/**********************************************************************\

 Copyright 2012 Diggory Blake

 This file is part of klip-engine

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

\**********************************************************************/
#pragma once

#define NOMINMAX

#include <d3d9.h>
#include <d3dx9.h>
#include <Windows.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

class kImageDX;
class kGraphicsDX;

#include "kimage.h"

class kImageDX : public kImage {
	friend class kGraphicsDX;
private:
	kGraphicsDX* _graphics;
	D3DPOOL _pool;
	IDirect3DSurface9* _surface;
	IDirect3DTexture9* _texture;
	void resetDevice(bool mode);

	virtual void doProcess(kRect* region, bool readonly, std::function<void (const kVec2i&, kColor&)> lambda) const;

protected:
	kImageDX(kGraphicsDX* graphics, IDirect3DSurface9* surface);
	kImageDX(kGraphicsDX* graphics, IDirect3DTexture9* texture);

public:
	inline IDirect3DSurface9* getSurfaceDX() const {
		return _surface;
	}
	inline IDirect3DTexture9* getTextureDX() const {
		return _texture;
	}
	virtual void save(kStream* stream, keImageFormat format) const;
	~kImageDX();
};
